package com.decent.ejfadmin.common.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * describe:销卡错误编码
 *
 * @author 陈豆豆
 * @date 2019/09/07
 */
public class SupplyCardError {
    /**
     * code失败码长度
     */
    public static final int CODE_LENGTH = 5;
    /**
     * 订单不存在
     */
    public static final String NOT_EXIST = "4000";
    /**
     * 链接超时
     */
    public static final String CONNECT_TIMEOUT = "90001";
    /**
     * 通用异常
     */
    private static final String COMMON_ERROR = "9999";
    /**
     * 输入的面值与卡实际面值不符
     */
    public static final String WRONG_UPLOAD_FACE = "23007";
    /**
     * 试充面值不符,暂停
     */
    public static final String BATCH_WRONG_FACE = "22000";
    /**
     * 卡状态预判初始或锁定或保留
     */
    public static final String JUDGE_UNKNOWN_CARD_STATUS = "21021";

    /**
     * 获取销卡备注
     *
     * @param code 错误/备注编码
     * @return 备注
     */
    public static String getFailReason(String code) {
        switch (code) {
            //卡密失败次数过多
            case "1001":
                //不支持卡面值
            case "1010":
                //不支持业务
            case "1011":
                //电信地方卡不支持
            case "1013":
                //卡密之前提交过
            case "1014":
                //相同卡密正在处理中
            case "1015":
                //卡号、卡密规则有误
            case "1017":
                //密码有误
            case "3001":
                //密码失效
            case "3002":
                //销卡失败
            case "3003":
                //未尝试销卡
            case "3005":
                return "2".concat(code);
            //处理中
            case "3006":
                //销卡成功
            case "3000":
                return "";
            default:
                boolean isNumeric = StringUtils.isNumeric(code);
                if (StringUtils.length(code) == CODE_LENGTH || !isNumeric) {
                    return code;
                }
                return COMMON_ERROR;
        }
    }
}
